<%@ page language="java" %>
<%@ page session="true" %>
<%@ page import="java.sql.*,java.io.*,com.jobportal.MyFunctions"%>

<HEAD>


	<script LANGUAGE="Javascript" SRC="Images/validate.js"></script>


	<LINK href="styles.css" type="text/css" rel="stylesheet">

</HEAD>
<BODY class=Grad>
<h3 align=center>User Registration</h3>

<%

	Connection con=null;
	ResultSet rs=null;
	Statement stmt=null,stmt1=null,stmt2=null,stmt3=null,stmt4=null;
	String userid = request.getParameter("userid");	
	String password = request.getParameter("password");	
	int auth = 1;	
    String ContactID = "";	
	MyFunctions MF = new MyFunctions();
	ContactID = MF.genNextID("contactinformation","ContactID","ConID");
    String FirstName = request.getParameter("FirstName");	
	String LastName = request.getParameter("LastName");	
	String Email = request.getParameter("Email");	
	String ContactNumber = request.getParameter("ContactNumber");	
	String CurrentLocation = request.getParameter("CurrentLocation");	
	String Address = request.getParameter("Address");	
	String PersonalID = "";	
	PersonalID = MF.genNextID("personalinformation","PersonalID","PerID");
	String DateOfBirth = request.getParameter("DateOfBirth");	
	String Gender = request.getParameter("Gender");	
	String EducationalID = "";	
	EducationalID = MF.genNextID("educationaldetails","EducationalID","EduID");
	String BasicQualification = request.getParameter("BasicQualification");	
	String PercentageBQ = request.getParameter("PercentageBQ");
	String YearOfPassBQ = request.getParameter("YearOfPassBQ");
	String UniversityBQ = request.getParameter("UniversityBQ");	
	String PostGraduation = request.getParameter("PostGraduation");
	String Percentage = request.getParameter("Percentage");	
	String YearOfPass = request.getParameter("YearOfPass");
	String University = request.getParameter("University");	
	String ProfessionalID = "";	
	ProfessionalID = MF.genNextID("professionalinformation","ProfessionalID","ProID");

	String TotalExperience = "0";
	String Year = request.getParameter("Year");	
	String Months = request.getParameter("Months");	
	/*
	double dYear=0,dMonths=0;
	if(Year!=null){
		 dYear = Double.parseDouble(Year);
	}
	if(Months!=null){
		 dMonths = Double.parseDouble(Months);
	}
	double TExp = dYear+dMonths/12;
	*/
	TotalExperience = Year+"."+Months;
	String AnnualSalary = request.getParameter("AnnualSalary");	
	String FunctionalArea = request.getParameter("FunctionalArea");	
	String CompanyName = request.getParameter("CompanyName");	
	String KeySkills = request.getParameter("KeySkills");	
	String ResumeTitle = request.getParameter("ResumeTitle");
	String TextResume = request.getParameter("TextResume");	
	String FilePath = request.getParameter("ResumePath");	
	String FileName = FilePath.substring(FilePath.lastIndexOf("\\"),FilePath.length());

	String JobID = request.getParameter("JobID");

	try{
			
			/* Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			con = DriverManager.getConnection("jdbc:odbc:jobportal","root",""); */

			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jobmiller","root","root");

			stmt =  con.createStatement();
			String Query = "Insert into login values('"+userid+"','"+password+"',"+auth+")";
			int result = stmt.executeUpdate(Query);
            System.out.println(Query);
           
			stmt1=con.createStatement();
            String Query1 = "Insert into contactinformation values('"+ContactID+"','"+userid+"','"+FirstName+"','"+LastName+"','"+Email+"','"+ContactNumber+"','"+CurrentLocation+"','"+Address+"')";
			int result1=stmt1.executeUpdate(Query1);
     		System.out.println(Query1);
			
			stmt2=con.createStatement();
			String Query2 = "Insert into personalinformation values('"+PersonalID+"','"+userid+"','"+DateOfBirth+"','"+Gender+"')";
			int result2=stmt2.executeUpdate(Query2);
     		System.out.println(Query2);
			
			stmt3=con.createStatement();
			String Query3 = "Insert into educationaldetails values('"+EducationalID+"','"+userid+"','"+BasicQualification+"','"+PercentageBQ+"','"+YearOfPassBQ+"','"+UniversityBQ+"','"+PostGraduation+"','"+Percentage+"','"+YearOfPass+"','"+University+"')";
			int result3=stmt3.executeUpdate(Query3);
     		System.out.println(Query3);

			stmt4=con.createStatement();
			String Query4 = "Insert into professionalinformation values('"+ProfessionalID+"','"+userid+"','"+TotalExperience+"','"+AnnualSalary+"','"+FunctionalArea+"','"+CompanyName+"','"+KeySkills+"','"+ResumeTitle+"','"+FileName+"','"+TextResume+"')";
			System.out.println(Query4);
			int result4=stmt4.executeUpdate(Query4);
     		System.out.println(Query4);

			if( result > 0)	{
				if(JobID==null|| JobID.equals("")){
				%>
					<P align=center><FONT COLOR="green" face="Times new roman">
						<I>You have successfully registered,Please login to proceed</I></FONT> 
					</P>
				<%
				}else{
				%>
					<P align=center><FONT COLOR="green" face="Times new roman">
						<I>You have successfully registered, Click on Apply Now to apply for the selected job</I></FONT> 
						<BR><BR>
						<INPUT TYPE="Button" onclick="location.href='ApplyJob.jsp?JobID=<%=JobID%>&userid=<%=userid%>'" value="Apply Now" Class="Button">
						</P>
				<%}
			}
			else{
				%><h3 align=center>Error in updating..please try again</h3><% 
			}
			stmt.close();
			stmt1.close();
			stmt2.close();
			stmt3.close();
			stmt4.close();
			con.close();
		}catch(Exception e){
			stmt.close();
			con.close();
			%><%=e%><%
		}
	
%>
</BODY>


